package operator.transfer;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import util.Printer;

class WindowOperator {

    public static void main(String[] args) {
        window1();
        window2();
    }

    // count = skip
    static void window1() {
        Observable.range(1, 10)
                .window(2)
                .subscribe(new Consumer<Observable<Integer>>() {
                    @Override
                    public void accept(Observable<Integer> integerObservable) throws Exception {
                        integerObservable.subscribe(new Consumer<Integer>() {
                            @Override
                            public void accept(Integer integer) throws Exception {
                                Printer.print(integer.toString());
                                Printer.print("-----------------");
                            }
                        });
                    }
                });
    }

    //从发射第一次count数据开始，按步长再次发射count
    static void window2() {
        Observable.range(1, 10)
                .window(2, 4)
                .subscribe(new Consumer<Observable<Integer>>() {
                    @Override
                    public void accept(Observable<Integer> integerObservable) throws Exception {
                        integerObservable.subscribe(new Consumer<Integer>() {
                            @Override
                            public void accept(Integer integer) throws Exception {
                                Printer.print(integer.toString());
                            }
                        });
                    }
                });
    }


}
